package com.xiaogao.security.config;

import com.xiaogao.common.utils.RedisUtils;
import com.xiaogao.security.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    private static final String[] array = {"/", "/login"};

    @Autowired
    private RedisUtils redisUtils;

    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor(redisUtils));
        //拦截所有路径,/**表示匹配多层地址
        registration.excludePathPatterns(array).addPathPatterns("/**");
    }
}